<template>
  <div class="warning-monitor">
    <el-row :gutter="20">
      <el-col :span="12">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>实时预警列表</span>
              <el-button type="primary" size="small" @click="refreshAlerts">刷新预警</el-button>
            </div>
          </template>
          <div class="alert-list">
            <div v-for="alert in alertList" :key="alert.id" :class="['alert-item', alert.level]"
              @click="handleAlert(alert)">
              <div class="alert-header">
                <span class="alert-type">{{ alert.type }}</span>
                <span class="alert-time">{{ alert.time }}</span>
              </div>
              <div class="alert-message">{{ alert.message }}</div>
              <div class="alert-actions">
                <el-button v-if="alert.status === 'pending'" size="mini" type="primary"
                  @click.stop="handleAlert(alert)">
                  处理
                </el-button>
                <el-tag v-else size="small" type="success">已处理</el-tag>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref, onMounted, nextTick } from 'vue'
import * as echarts from 'echarts'
import { ElMessage } from 'element-plus'
import { WarningMonitorConfig } from './WarningMonitor/config.js'
import './WarningMonitor/style.css'

// 配置
const config = WarningMonitorConfig

// 预警列表数据
const alertList = ref(config.alertList.alerts)

// 处理预警
const handleAlert = (alert) => {
  if (alert.status === 'pending') {
    alert.status = 'handled'
    ElMessage.success(`预警 "${alert.type}" 已处理`)
  }
}

// 刷新预警列表
const refreshAlerts = () => {
  // 模拟刷新预警数据
  ElMessage.success('预警列表已刷新')
}

// 组件挂载时初始化
onMounted(() => {
  console.log('组件已挂载，所有图表已删除，只保留预警列表')
})
</script>

<style scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>